import sys

import xlrd

from model.OneScoreRank import OneScoreRank


# 复制2022年的《一分一档表》数据到2023年，因为正式的2023年一分一档数据还没出来
def to_copy():
    oneScoreRank = OneScoreRank()
    old_year = 2022
    new_year = 2023
    data = oneScoreRank.getList(old_year)
    total_list = list()
    for index, row in enumerate(data):
        print(index, row)
        row['year'] = new_year
        del row['id']
        total_list.append(row)

    oneScoreRank.toInsertBatch(total_list)


# 导入2023年理科一分一档表（全国）
def import_one_score_rank_like():
    data = xlrd.open_workbook('../static/excel_2023/like2023.xls')
    table = data.sheet_by_name('Sheet1')
    rowNum = table.nrows
    colNum = table.ncols
    print(rowNum, colNum)
    oneScoreRank = OneScoreRank()
    for i in range(rowNum):
        if i > 2:
            row = dict()
            row['year'] = 2023
            row['type'] = 1  # 文理科 1理科 2文科
            row['score'] = int(table.cell(i, 0).value)
            row['num'] = int(table.cell(i, 1).value)
            row['total_num'] = int(table.cell(i, 2).value)
            row['rank'] = int(table.cell(i, 3).value)
            print(row)
            oneScoreRank.toInsert(row)


# 导入2023年文科一分一档表
def import_one_score_rank_wenke():
    data = xlrd.open_workbook('../static/excel_2023/wenke2023.xls')
    table = data.sheet_by_name('Sheet1')
    rowNum = table.nrows
    colNum = table.ncols
    print(rowNum, colNum)
    oneScoreRank = OneScoreRank()
    for i in range(rowNum):
        if i > 2:
            row = dict()
            row['year'] = 2023
            row['type'] = 2  # 文理科 1理科 2文科
            row['score'] = int(table.cell(i, 0).value)
            row['num'] = int(table.cell(i, 1).value)
            row['total_num'] = int(table.cell(i, 2).value)
            row['rank'] = int(table.cell(i, 3).value)
            oneScoreRank.toInsert(row)


if __name__ == "__main__":
    import_one_score_rank_wenke()
